package top.xierongsheng.user.validate.impl;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import org.springframework.beans.factory.annotation.Autowired;
import top.xierongsheng.user.model.SysUser;
import top.xierongsheng.user.service.IUserService;
import top.xierongsheng.user.validate.ValidUser;



public class UserValidator implements ConstraintValidator<ValidUser, String> {

    @Autowired
    private IUserService userService;

    @Override
    public void initialize(ValidUser constraintAnnotation) {
    }

    @Override
    public boolean isValid(String param, ConstraintValidatorContext constraintValidatorContext) {
        SysUser sysUser = userService.getById(param);
        if (sysUser == null) {
            return false;
        }
        return true;
    }
}
